package org.example.chapter8.server.handler;

import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;
import org.example.chapter8.protocol.request.LoginRequestPacket;
import org.example.chapter8.protocol.request.LogoutRequestPacket;
import org.example.chapter8.protocol.response.LoginResponsePacket;
import org.example.chapter8.protocol.response.LogoutResponsePacket;
import org.example.chapter8.session.Session;
import org.example.chapter8.utils.IDUtil;
import org.example.chapter8.utils.SessionUtil;

import java.util.Date;

public class LogoutRequestHandler extends SimpleChannelInboundHandler<LogoutRequestPacket> {

    public static final LogoutRequestHandler INSTANCE = new LogoutRequestHandler();

    private LogoutRequestHandler() {

    }

    @Override
    protected void channelRead0(ChannelHandlerContext ctx, LogoutRequestPacket requestPacket) throws Exception {
        SessionUtil.unBindSession(ctx.channel());
        LogoutResponsePacket responsePacket = new LogoutResponsePacket();
        responsePacket.setSuccess(true);
        ctx.writeAndFlush(responsePacket);
    }

}
